package view;

import controller.RegisterListener;
import controller.SignInListener;

import javax.swing.*;
import java.awt.*;

public class Register extends JDialog {

    private JButton button1,button2,button3;;
    private JLabel label1,label2,label3,label,label4,labelName,labelGender,labelPN;
    //文本框
    private JTextField tfNum,tfPN,tfName,tfGender;
    //密码
    private JPasswordField tfPwd;
    //按钮
    private JPanel panel1;
    private MainJFrame frame;
    private  JLayeredPane pane;
    private ImageIcon image;

    private RegisterListener listener;

    public Register() {
        this.frame = frame;
        listener=new RegisterListener(this);
        pane = new JLayeredPane();
        panel1 = new JPanel();
        image = new ImageIcon("src/image/photo9.png");
        label1 = new JLabel("欢迎注册");
        label4=new JLabel("每一天 乐在阅读");
        label2=new JLabel("学 号：");
        label3=new JLabel("密 码：");
        labelName=new JLabel("姓 名:");
        labelGender=new JLabel("年 级:");
        labelPN=new JLabel("电 话：");
        tfNum=new JTextField(15);
        tfPwd=new JPasswordField(15);
        tfName=new JTextField(15);
        tfGender=new JTextField(15);
        tfPN=new JTextField(15);
        button1 = new JButton(new ImageIcon("src/image/photo13.png"));
        button2 = new JButton(new ImageIcon("src/image/photo12.png"));

        button1.setPressedIcon(new ImageIcon("src/image/photo10.png"));
        button2.setPressedIcon(new ImageIcon("src/image/photo11.png"));

        button1.setActionCommand("1");
        button2.setActionCommand("2");

        label1.setFont( new Font ( "隶书" , Font.BOLD , 25));
        label4.setFont( new Font ( "隶书" , Font.BOLD , 25));
        label2.setFont( new Font ( "宋体" , Font.BOLD , 18));
        label3.setFont( new Font ( "宋体" , Font.BOLD , 18));
        labelGender.setFont( new Font ( "宋体" , Font.BOLD , 18));
        labelName.setFont( new Font ( "宋体" , Font.BOLD , 18));
        labelPN.setFont( new Font ( "宋体" , Font.BOLD , 18));
        button1.setContentAreaFilled(false);//透明
        button1.setBorderPainted(false);//去边框
        button1.setFocusPainted(false);//去焦点
        button2.setContentAreaFilled(false);//透明
        button2.setBorderPainted(false);//去边框
        button2.setFocusPainted(false);//去焦点

        button1.addActionListener(listener);
        button2.addActionListener(listener);

        //设置透明
        label1.setOpaque(false);
        label2.setOpaque(false);
        label3.setOpaque(false);
        label4.setOpaque(false);
        labelPN.setOpaque(false);
        labelName.setOpaque(false);
        labelGender.setOpaque(false);
        tfNum.setOpaque(false);
        tfPwd.setOpaque(false);
        tfName.setOpaque(false);
        tfPN.setOpaque(false);
        tfGender.setOpaque(false);
//        button3.setOpaque(false);
//        button2.setOpaque(false);
//        button1.setOpaque(false);

        label = new JLabel(image);        //把背景图片添加到标签里
        panel1.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());   //把标签设置为和图片等高等宽
        panel1 = (JPanel) this.getContentPane();    //把我的面板设置为内容面板
        panel1.add(label);

        label1.setBounds(20, 0, 300, 50);
        label4.setBounds(20, 20, 300, 50);
        label2.setBounds(30,50,80,50);
        tfNum.setBounds(100,67,100,20);
        label3.setBounds(30,80,80,50);
        tfPwd.setBounds(100,97,100,20);
        labelName.setBounds(30,110,80,50);
        tfName.setBounds(100,127,100,20);
        labelGender.setBounds(30,140,80,50);
        tfGender.setBounds(100,157,100,20);
        labelPN.setBounds(30,170,80,50);
        tfPN.setBounds(100,187,100,20);
        button1.setBounds(300,100,60,40);
        button2.setBounds(300,150,60,40);

        pane.add(panel1, JLayeredPane.DEFAULT_LAYER);
        pane.add(label1, JLayeredPane.MODAL_LAYER);
        pane.add(label4, JLayeredPane.MODAL_LAYER);
        pane.add(label2, JLayeredPane.MODAL_LAYER);
        pane.add(label3, JLayeredPane.MODAL_LAYER);
        pane.add(labelPN, JLayeredPane.MODAL_LAYER);
        pane.add(labelGender, JLayeredPane.MODAL_LAYER);
        pane.add(labelName, JLayeredPane.MODAL_LAYER);
        pane.add(tfName, JLayeredPane.MODAL_LAYER);
        pane.add(tfNum,JLayeredPane.MODAL_LAYER);
        pane.add(tfPwd,JLayeredPane.MODAL_LAYER);
        pane.add(tfGender,JLayeredPane.MODAL_LAYER);
        pane.add(tfPN,JLayeredPane.MODAL_LAYER);
        pane.add(button1,JLayeredPane.MODAL_LAYER);
        pane.add(button2,JLayeredPane.MODAL_LAYER);

        this.setTitle("注册界面");
        this.setBounds(100, 100, image.getIconWidth(), image.getIconHeight());
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLayeredPane(pane);
        this.setVisible(true);
    }

    public JTextField getTfNum() {

        return tfNum;
    }

    public JTextField getTfPwd() {

        return tfPwd;
    }

    public JTextField getTfPN() {
        return tfPN;
    }

    public JTextField getTfName() {
        return tfName;
    }

    public JTextField getTfGender() {
        return tfGender;
    }

//    public JTextField getTfType() {
//        return tfType;
//    }
}